// pages/activity/detail/index.js
var WxParse = require('../../../miniprogram_npm/wxParse/wxParse')
import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog';

var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    item:{},
    id:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      id:options.id
    })
    this.onShow();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const that = this
 
    app.api.get(app.getUrl('activity')+'/'+this.data.id).then((res)=>{
        that.setData({
          item:res
        });
        that.parseHtml(res.content);
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onShareTimeline(){

  },
  parseHtml(html) {
    const that = this
    WxParse.wxParse('article', 'html', html, that, 5);
  },
  setTitle(title='') {
    wx.setNavigationBarTitle({
      title: title,
    })   
  },//活动报名
  applyActivity() {
    const that = this
    console.log('activity',that.data.item)
    const data = {
      activity_id:that.data.item.id
    }
    app.api.post(app.getUrl('activity.apply'), data).then((res)=>{
      console.log('ok', res)
      Dialog.alert({
        title:'提示',
        message:res.message
      })
    })
  },
  getRecord() {

  }
})